package org.hhchat.others.toutiao.p2018;

import java.util.Arrays;
import java.util.List;
import java.util.Scanner;
import java.util.stream.Collectors;

/**
 * Created this one by huminghao on 2018/4/15.
 */
public class Main01 {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int cases = scanner.nextInt();
        scanner.nextLine();
        while (cases-- > 0) {
            String string  = scanner.nextLine();
            List<Integer> list = Arrays.stream(string.split("\\s")).map(Integer::valueOf).collect(Collectors.toList());
            int k = list.get(0);
            list.remove(0);
            int n = list.size() - 1;
            int total = n * (n - 1) / 2;
            int temp = 0;
            int cur = 0;
            int gap = 0;
            int gap_num = n - 1;
            while (cur < total && k > cur) {
                if (k > cur) {
                    cur = cur + gap_num;
                    gap_num = gap_num - 1;
                    gap++;
                }
            }
            temp = k - (cur - gap_num);
            System.out.print(list.get(n - temp - gap)+" ");
            System.out.println(list.get(n - temp));
        }

    }

}
